<?php


namespace App\Http\Requests\Order\Index;


use App\Rules\IdNumberRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreRequest extends FormRequest
{
    /**
     * @return array
     * @author luffyzhao@vip.126.com
     */
    public function rules()
    {
        return static::rulesStatic();
    }

    /**
     * @return array
     */
    public static function rulesStatic(){
        return [
            'number' => ['required', 'alpha_dash', 'max:64'],
            'customer_id' => ['required', Rule::exists('customers', 'id')->where('status', 2)],
            'express_id' => ['required',
                Rule::exists('express', 'id')->where('status', 0)],
            'freight' => ['required', 'numeric'],
            'buyer_name' => ['required', 'max:20'],
            'receiving_name' => ['required', 'max:20'],
            'receiving_phone' => ['required', 'max:20'],
            'buyer_type' => ['required', 'in:1'],
            'buyer_number' => ['required', 'size:18', new IdNumberRule()],
            'buyer_telephone' => ['required', 'max:20'],
            'areas' => ['required', 'array', 'size:3'],
            'address' => ['required', 'max:200'],
            'ebc_code' => ['required', 'size:10'],
            'ebc_name' => ['required', 'max:200'],
            'ebp_code' => ['required', 'size:10'],
            'ebp_name' => ['required', 'max:200'],
            'remark' => ['nullable', 'max:200'],
            'products' => ['required', 'array'],
            'products.*.code' => ['required', Rule::exists('products', 'code')
                ->where('status', 3)
                ->where('customer_id', request()->input('customer_id'))],
            'products.*.expire' => ['required', 'integer', 'in:0,1'],
            'products.*.attribute' => ['required', 'integer', 'in:0,1'],
            'products.*.expiry' => ['nullable', 'date'],
            'products.*.quantity' => ['required', 'integer'],
            'products.*.price' => ['required', 'numeric'],
        ];
    }

    public static function messagesStatic(){
        return [
            ''
        ];
    }
}
